#!/bin/bash

INTERVAL=2

function Init {
    local self_count=$(pgrep -cx "$(basename $0)")
    [ 0 -eq $? ] || exit 1
    [ 1 -eq $self_count ] || exit 1
    type sar > /dev/null || exit 1
}

function Main {
    cd $(dirname $0) || exit 1
    while sleep $INTERVAL; do
        for proc in $(find . -type f -name "mon_*" \
            -executable); do
            $proc &
        done
    done
}

# start
Init
Main

